//
//  AmuseViewController.swift
//  DouYuZB
//
//  Created by DSDL on 2017/2/7.
//  Copyright © 2017年 鼎商动力. All rights reserved.
//

import UIKit
private let kMenuViewH: CGFloat = 200
class AmuseViewController: BaseAnchorViewController {
    //MARK: - 懒加载属性
    fileprivate lazy var amuseVM : AmuseViewModel = AmuseViewModel()
    
    lazy var menuView: AmuseMenuView = {
        let menuView = AmuseMenuView.fromNib(nibName: "AmuseMenuView")
        menuView.frame = CGRect(x: 0, y: -kMenuViewH, width: kScreenW, height: kMenuViewH)
        return menuView as! AmuseMenuView
    }()
}
//MARK: - 设置UI
extension AmuseViewController{
    override func setupUI() {
        //1.调用super
        super.setupUI()
        //2.将amuseMenu添加到Collection 中
        collectionView.addSubview(menuView)
        collectionView.contentInset  = UIEdgeInsets(top: kMenuViewH, left: 0, bottom: 0, right: 0)
    }
}

//MARK: - 请求数据
extension AmuseViewController{
    override func loadData() {
        //1.给父类的ViewModel 赋值
        baseVM = amuseVM
        //2.请求数据
        amuseVM.loadAmuseData {
            self.collectionView.reloadData()
            //传值
            var tempGroup = self.amuseVM.anchorGroup
            tempGroup.removeFirst()
            self.menuView.groups = tempGroup
            
            //3.数据请求完成
            self.loadDataFinish()
        }
    }
}

